import pathToRegexp from 'path-to-regexp/index';
import {getRehearsal,getYLBM,getAllRoleTow,getMaillist,postRehearsal,deleteRehearsal,putRehearsal} from 'services/app';
export default {
    namespace: 'rehearsal',
    state: {
        pages:1,
        record:{},
    },
    subscriptions: {
        setupHistory ({ dispatch, history }) {
            history.listen((location) => {
                const match = pathToRegexp('/home').exec(location.pathname);
            });
        },
        setup ({ dispatch }) {},
    },
    effects: {
        //查看登录状态
        *getRehearsal ({ payload }, { call, put }){
            const {data,total} = yield call(getRehearsal, payload);
            yield put({ type: 'save', payload: {getRehearsalData:data,total:total,pages:payload.pageNumber}});
        },
        //新增获取通讯录
        *getTXL ({ payload }, { call, put }){
            const {data} = yield call(getMaillist, {
                name:"",
                phone :"",
                pageNumber :0,
                pageSize :0,
            });
            yield put({ type: 'save', payload: {getTXLData:data}});
        },
        //获取部门
        *getYLBM ({ payload }, { call, put }){
            const {data} = yield call(getAllRoleTow, {o_id:'222222'});
            yield put({ type: 'save', payload: {getYLBMData:data}});
        },
        //添加演练计划
        *postRehearsal ({ payload }, { call, put }){
            const data = yield call(postRehearsal, payload);
            if(data.code == 0){
                yield put({ type: 'save', payload: {pages:0,view:false}});
            }
        },
        //删除演练计划
        *deleteRehearsal ({ payload }, { call, put }){
            const data = yield call(deleteRehearsal, payload);
            if(data.code == 0){
                yield put({ type: 'save', payload: {pages:0}});
            }
        },
        //修改演练计划
        *putRehearsal ({ payload }, { call, put }){
            const data = yield call(putRehearsal, payload);
            if(data.code == 0){
                yield put({ type: 'save', payload: {pages:0,view:false}});
            }
        },
    },
    reducers: {
        save (state, { payload }) {
            return { ...state, ...payload };
        },
    },
};
